﻿// //------------------------------------------------------------------------------
// // <copyright file="" company="Dascoba Development">
// //  Copyright © Dascoba Development 2010
// // </copyright>
// //------------------------------------------------------------------------------
namespace Dascoba.Umb.FileManager.Actions
{
    using Dascoba.Umb.FileManager.Support;

    using umbraco;
    using umbraco.interfaces;

    public class ActionDeleteFile : IAction
    {
        /// <summary>
        ///   Initializes a new instance of the <see cref = "ActionDeleteFile" /> class.
        /// </summary>
        private ActionDeleteFile()
        {
        }

        /// <summary>
        ///   Gets the instance.
        /// </summary>
        /// <value>The instance.</value>
        public static ActionDeleteFile Instance
        {
            get
            {
                // return singleton
                return new ActionDeleteFile();
            }
        }

        #region Implementation of IAction

        /// <summary>
        ///   Gets the letter.
        /// </summary>
        /// <value>The letter.</value>
        public char Letter
        {
            get
            {
                // U+0189: Latin Capital Letter African D
                return 'Ɖ';
            }
        }

        /// <summary>
        ///   Gets a value indicating whether [show in notifier].
        /// </summary>
        /// <value><c>true</c> if [show in notifier]; otherwise, <c>false</c>.</value>
        public bool ShowInNotifier
        {
            get
            {
                return true;
            }
        }

        /// <summary>
        ///   Gets a value indicating whether this instance can be permission assigned.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance can be permission assigned; otherwise, <c>false</c>.
        /// </value>
        public bool CanBePermissionAssigned
        {
            get
            {
                return true;
            }
        }

        /// <summary>
        ///   Gets the icon.
        /// </summary>
        /// <value>The icon.</value>
        public string Icon
        {
            get
            {
                return string.Format("/../../{0}/images/deletefile.png", Constants.FileManagerFolderName);
            }
        }

        /// <summary>
        ///   Gets the alias.
        /// </summary>
        /// <value>The alias.</value>
        public string Alias
        {
            get
            {
                return "deleteFile";
            }
        }

        /// <summary>
        ///   Gets the name of the js function.
        /// </summary>
        /// <value>The name of the js function.</value>
        public string JsFunctionName
        {
            get
            {
                if (Util.SupportsJQueryTree)
                {
                    return "DeleteFile('" + ui.Text("actions", this.Alias) + "','" + ui.Text("fileman", "deleteFileAreYouSure") + "')";
                }
                return "parent.DeleteFile('" + ui.Text("actions", this.Alias) + "','" + ui.Text("fileman", "deleteFileAreYouSure") + "')";
            }
        }

        /// <summary>
        ///   Gets the js source.
        /// </summary>
        /// <value>The js source.</value>
        public string JsSource
        {
            get
            {
                if (Util.SupportsJQueryTree)
                {
                    return @"
                    function DeleteFile(title, question) {
                        if (nodeID != '-1' && nodeType != '') {
                            var response = confirm(question.replace('[filename]', '""' + nodeID + '""'));
                            if (response) {
                                openModal('~/umbraco/filemanager/Dialogs/DeleteItem.aspx?type=file&item=' + encodeURI(nodeID), title, 130, 400);
                            }
                            return false;
                        }
                    }";
                }

                return string.Format("{0}/js/deleteFile.js", Constants.FileManagerGlobalUrl);
            }
        }

        #endregion
    }
}